package com.itheima.pinda.controller.transportline;


import com.itheima.pinda.DTO.entity.dto.PdTransportLineDTO;
import com.itheima.pinda.DTO.entity.pojo.transportline.PdTransportLine;
import com.itheima.pinda.DTO.entity.vo.Results;
import com.itheima.pinda.DTO.entity.vo.StatusCode;
import com.itheima.pinda.feign.service.transportline.PdTransportLineService;
import com.itheima.pinda.utils.CustomIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 线路表 前端控制器
 * </p>
 *
 * @author xy
 * @since 2021-11-15
 */
@RestController
@RequestMapping("/base/transportLine")
public class PdTransportLineController {

    @Autowired
    private CustomIdGenerator idGenerator;

    @Autowired
    private PdTransportLineService transportLineService;

    /**
     * 线路管理查询
      * @param lineNumber
     * @param name
     * @param lineTypeId
     * @return
     */
    @PostMapping("/")
    public Results<List<PdTransportLineDTO>> findAll(@RequestBody String lineNumber ,
                                               @RequestBody String name,
                                               @RequestBody String lineTypeId){
        List<PdTransportLineDTO> lineDTOS = transportLineService.findAll(lineNumber, name, lineTypeId);

        return new Results<List<PdTransportLineDTO>>(true, StatusCode.OK,"查询成功 ", lineDTOS);
    }


    @PostMapping("/update")
    public Results update(@RequestBody PdTransportLine transportLine){

        Integer b = transportLineService.updateTransportLine(transportLine);

        return b>0?new Results<>(true, StatusCode.OK,"修改成功 ", null)
                :new Results(false,StatusCode.ERROR,"修改失败",null);
    }


    @PostMapping("/insert")
    public Results insert(@RequestBody PdTransportLine transportLine){

        transportLine.setId(idGenerator.nextId(transportLine)+"");
        Integer b = transportLineService.insertTranssportLine(transportLine);

        return b>0?new Results<>(true, StatusCode.OK,"添加成功 ", null)
                :new Results(false,StatusCode.ERROR,"添加失败",null);
    }

    @PostMapping("/disable")
    public Results disable(@RequestBody String lineId){

        Integer b = transportLineService.disableTransportLine(lineId);

        return b>0?new Results<>(true, StatusCode.OK,"禁用成功 ", null)
                :new Results(false,StatusCode.ERROR,"禁用失败",null);
    }

}
